package com.mytest.leetcode.lcp;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Collections;

@Slf4j
public class Solution28 {

    public static void main(String[] args) {
        Solution28 solution28 = new Solution28();
        int[] nums = {2,2,1,9};
        int target = 10;
        int result = solution28.purchasePlans(nums, target);
        log.info("{}", result);
    }

    public int purchasePlans(int[] nums, int target) {
        Arrays.sort(nums);
//        log.info("{}", nums);
        int i = 0;
        int j = nums.length - 1;
        int result = 0;
        while (i<j) {
            if (target < nums[i] + nums[j]) {
                j --;
            } else {
                result = result +j-i;
                i++;
            }
            result %= 1000000007;
        }
        return result%1000000007;
    }
}
